package panel

import "code.google.com/p/freetype-go/freetype/raster"

type Common struct {
    Parental View
    WH Size
    Offset Point
}

func (c *Common) Parent(p View) {
    c.Parental = p
}

type Size raster.Point
type Point raster.Point

func (p Point) Add(other Point) Point {
	return Point(raster.Point(p).Add(raster.Point(other)))
}

func (p Point) Sub(other Point) Point {
	return Point(raster.Point(p).Sub(raster.Point(other)))
}

func (s Size) Sub(other Size) Size {
	return Size(Point(s).Sub(Point(other)))
}

func (s Size) Div(n int) Size {
	return Size{s.X / raster.Fix32(n), s.Y / raster.Fix32(n)}
}

func (p Point) AddX(dx raster.Fix32) Point {
	p.X += dx
	return p
}

func (p Point) SubX(dx raster.Fix32) Point {
	p.X -= dx
	return p
}

func (c *Common) Floaty(xy Point, text string) {
	c.Parental.Floaty(xy.Add(c.Offset), text)
}

func (c *Common) At(xy Point) View {
	// Log("Common.At:", xy)
    return c
}

func (c *Common) GainFocus(xy Point) {
}

func (c *Common) LoseFocus()  {
}

func (c *Common) Resize(wh Size, offset Point) {
    c.WH, c.Offset = wh, offset
}

func (c *Common) Cursor(xy Point) {
    c.Parental.Cursor(xy.Add(c.Offset)) 
}

func (c *Common) Put(xy Point, back Paper, p Pen, rune int) {
    c.Parental.Put(xy.Add(c.Offset), back, p, rune)
}

func (c *Common) PutString(xy Point, back Paper, p Pen, text string) {
    c.Parental.PutString(xy.Add(c.Offset), back, p, text)
}

func (c *Common) FocusForClick(xy Point) View {
    return c
}

func (c *Common) Refresh() {
	Log("Common.Refresh")
}

func (c *Common) Key(rune int) View {
	return c
}

func (c *Common) Box(xy1 Point, xy2 Point) {
	c.Parental.Box(xy1.Add(c.Offset), xy2.Add(c.Offset))
}

func (c *Common) Show(message string) {
	c.Parental.Show(message)
}
